package com.eurabia.eggchat.controller.admin;


import com.eurabia.eggchat.VO.ResultVO;
import com.eurabia.eggchat.pojo.SysEggchatRole;
import com.eurabia.eggchat.pojo.SysEggchatRolePermission;
import com.eurabia.eggchat.pojo.form.SysEggchatRolePermissionForm;
import com.eurabia.eggchat.pojo.query.SysEggchatRolePermissionQuery;
import com.eurabia.eggchat.service.SysEggchatRolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;

/**
 * SysEggchatRolePermissionController 
 */
@Controller
@RequestMapping("/sysEggchatRolePermission")
public class SysEggchatRolePermissionController {
    private static final String LIST_PAGE = "modules/sysEggchatRolePermission/list";
	private static final String SHOW_PAGE = "modules/sysEggchatRolePermission/show";
    private static final String ADD_PAGE = "modules/sysEggchatRolePermission/add";
    private static final String EDIT_PAGE = "modules/sysEggchatRolePermission/edit";
    @Autowired
    private SysEggchatRolePermissionService sysEggchatRolePermissionService;
	
	/**
     * SysEggchatRolePermission页面
     */
    @RequestMapping(value = "/listPage", method = RequestMethod.GET)
    public final String listPage() {
        return LIST_PAGE;
    }

    /**
     * 查询 SysEggchatRolePermission
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public final ResultVO list(final SysEggchatRolePermissionQuery query) {
        return new ResultVO(sysEggchatRolePermissionService.findByPage(query));
    }

    /**
     * 查询 SysEggchatRolePermission
     */
    @RequestMapping(value = "/listAll", method = RequestMethod.GET)
    @ResponseBody
    public final ResultVO listAll(final SysEggchatRolePermissionQuery query) {
        return new ResultVO(sysEggchatRolePermissionService.find(query));
    }

    /**
     * 查看 SysEggchatRolePermission
     */
    @GetMapping(value = "/show_{id}")
    @ResponseBody
    public final ResultVO showOne(@PathVariable("id") final String id) {
        ResultVO resultVO = new ResultVO();
        ArrayList<SysEggchatRolePermission> sysEggchatRolePermissions = new ArrayList<>();
        SysEggchatRolePermission sysEggchatRolePermission = sysEggchatRolePermissionService.get(id);
        sysEggchatRolePermissions.add(sysEggchatRolePermission);
        resultVO.setData(sysEggchatRolePermissions);
        return resultVO;
    }

    /**
     * 新增 SysEggchatRolePermission
     */
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public final String addPage() {
        return ADD_PAGE;
    }

    /**
     * 新增 SysEggchatRolePermission
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO add(final SysEggchatRolePermissionForm form) {
        sysEggchatRolePermissionService.add(form);
        return new ResultVO();
    }

    /**
     * 修改 SysEggchatRolePermission
     */
    @RequestMapping(value = "/edit_{id}", method = RequestMethod.GET)
    public final ModelAndView editPage(@PathVariable("id") final String id) {
        ModelAndView mav = new ModelAndView(EDIT_PAGE);
        mav.addObject("result", sysEggchatRolePermissionService.get(id));
        return mav;
    }

    /**
     * 修改 SysEggchatRolePermission
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO edit(final SysEggchatRolePermissionForm form) {
        sysEggchatRolePermissionService.update(form);
        return new ResultVO();
    }

    /**
     * 根据id删除 SysEggchatRolePermission
     */
    @RequestMapping(value = "/delete_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO delete(@PathVariable("id") final String id) {
        sysEggchatRolePermissionService.delete(id);
        return new ResultVO();
    }

    /**
     * 启用 SysEggchatRolePermission
     */
    @RequestMapping(value = "/enabled_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO enabled(@PathVariable("id") final String id) {
        sysEggchatRolePermissionService.changeEnabled(id, 1);
        return new ResultVO();
    }

    /**
     * 停用 SysEggchatRolePermission
     */
    @RequestMapping(value = "/disabled_{id}", method = RequestMethod.POST)
    @ResponseBody
    public final ResultVO disabled(@PathVariable("id") final String id) {
        sysEggchatRolePermissionService.changeEnabled(id, 2);
        return new ResultVO();
    }
}